package org.windblog.core.servlet.option;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.windblog.core.entity.Option;
import org.windblog.core.OptionService;
import java.util.Enumeration;


@SuppressWarnings("serial")
public class SetOptionServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		@SuppressWarnings("unchecked")
		Enumeration<String> paramnames = req.getParameterNames();
		while(paramnames.hasMoreElements())
		{
			String pname = paramnames.nextElement();
			if(pname.startsWith("opt_"));
			{
				Option curoption  = OptionService.getOption(pname.substring(4));
				curoption.setValue(req.getParameter(pname));
				req.setAttribute("msg", "Options modified!");
			}
		}
		resp.sendRedirect("options.jsp");
	}


}
